package test033;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class App4 {

    public static void main( String[] args ) {

        SqlSessionFactory factory = null;
        try {
            InputStream inputStream = Resources.getResourceAsStream("config.xml");
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            //方法1：采用xml配置文件生成  【店长推荐】
            factory = builder.build(inputStream);
            System.out.println("2.建造工厂"+factory);
        } catch (Exception e) {
            e.printStackTrace();
        }


        SqlSession sqlSession = factory.openSession();
        System.out.println("3.session："+sqlSession);


        //方案1：
        StudentDao2 dao2 = sqlSession.getMapper(StudentDao2.class);

        Student2 student2 = dao2.selectStudentWithAddress();
        System.out.println(student2.getName());
        System.out.println(student2.getAddress());
        System.out.println(student2.getAddress().getAddrId());
        System.out.println(student2.getAddress().getCity());

        sqlSession.commit();
        sqlSession.close();


        //.....................
        //方案2：
        //Student student2 = sqlSession.selectOne("test033.StudentDao.findStudentById", 1);




    }
}
